﻿@model Retete.ViewModels.StergeProdusViewModel
@{
    ViewBag.Title = "Stergere produs";
}

<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("#NumeProdusInlocuitor").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '@Url.Content("~/Autocomplete/Produse")',
                    dataType: "json",
                    data: { maxRows: 8, contains: request.term },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { value: item.Cod + ' ' + item.Nume, nume: item.Nume, id: item.ID, unitate: item.UnitateMasura, cod: item.Cod }
                        }));
                    }
                });
            },
            minLength: 2,
            delay: 50,
            select: function (event, ui) {
                IDProdusInlocuitor.value = ui.item.id;
                NumeProdusInlocuitor.value = ui.item.nume;
            }
        });
    });
</script>

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "form", name = "form" }))
{
    <table style="width: 100%">
        <tr>
            <td style="width: 190px; vertical-align: top; border-right-style: dashed; border-right-color: #CFCFCF; border-right-width: 1px;">
                <fieldset>
                    <legend>Activitati</legend>

                    <p class="toolbox"><a href="javascript:form.submit()">Accepta</a></p>
                    <p class="toolbox">@Html.ActionLink("Renunta", "Index")</p>
                </fieldset>
            </td>
            <td style="vertical-align: top;">
                @Html.ValidationSummary(false)

                <fieldset>
                    <legend>Detalii produs</legend>

                    <p>
                        @Html.LabelFor(model => model.Produs.Cod, "Cod si categorie")
                        @Html.TextBoxFor(model => model.Produs.Cod, new { style = "width: 80px;", @readonly = "readonly" })
                        @Html.TextBoxFor(model => model.Produs.Categorie, new { style = "width: 211px;", @readonly = "readonly" })
                        @Html.HiddenFor(model => model.Produs.ID)
                    </p>

                    <p>
                        @Html.LabelFor(model => model.Produs.Categorie, "Nume")
                        @Html.TextBoxFor(model => model.Produs.Nume, new { @readonly = "readonly" })
                    </p>
                </fieldset>
    
                <fieldset>
                    <legend>Retete in care apare produsul</legend>
                    
                    <table class="grid">
                        <thead>
                            <tr>
                                <th style="width: 70px">Cod</th>
                                <th>Produs</th>
                            </tr>
                        </thead>
        
                        <tbody>
                            @if (@Model.Referinte != null)
                            {
                                for (int i = 0; i < Model.Referinte.Count; i++)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayTextFor(element => element.Referinte[i].Reteta.Cod)
                                            @Html.HiddenFor(element => element.Referinte[i].Reteta.Cod)
                                        </td>
                                        <td>
                                            @Html.DisplayTextFor(element => element.Referinte[i].Reteta.Nume)
                                            @Html.HiddenFor(element => element.Referinte[i].Reteta.Nume)
                                            @Html.HiddenFor(element => element.Referinte[i].Reteta.MultiplicatorCantitati)
                                            @Html.HiddenFor(element => element.Referinte[i].Produs.PretCumparare)
                                            @Html.HiddenFor(element => element.Referinte[i].Produs.ID)
                                            @Html.HiddenFor(element => element.Referinte[i].Cantitate)
                                            @Html.HiddenFor(element => element.Referinte[i].ID)
                                            @Html.HiddenFor(element => element.Referinte[i].IDProdus)
                                            @Html.HiddenFor(element => element.Referinte[i].IDReteta)
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </fieldset>

                <fieldset>
                    <legend>Inlocuieste in retete cu produsul</legend>

                    <p>
                        @Html.LabelFor(model => model.NumeProdusInlocuitor, "Produs")
                        @Html.TextBoxFor(model => model.NumeProdusInlocuitor)
                        @Html.HiddenFor(model => model.IDProdusInlocuitor)
                    </p>
                </fieldset>
            </td>
        </tr>
    </table>
}